package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.pojo.CourseDTO;
import com.wang.pojo.Specialist;
import com.wang.response.PageResult;
import com.wang.response.Result;
import com.wang.response.ResultResponse;
import com.wang.service.SpecialistService;
import com.wang.mapper.SpecialistMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Service
@Transactional
public class SpecialistServiceImpl
    implements SpecialistService{
    @Autowired
    SpecialistMapper specialistMapper;


    @Override
    public ResultResponse addOrUpdateSpecialist(Specialist specialist) {
        if(specialist.getSpecialistId()==null){
            specialistMapper.insert(specialist);
            return ResultResponse.SUCCESS();
        }
        specialistMapper.updateById(specialist);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse getSpecialistAll(Integer pageNum, Integer pageSize) {
        Page<Specialist> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Specialist> queryWrapper = new QueryWrapper<>();
        Page<Specialist> page1 = specialistMapper.selectPage(page, queryWrapper);
        return ResultResponse.SUCCESS(page1.getRecords(),page1.getTotal());
    }

    @Override
    public ResultResponse delSpecialist(Integer specialistId) {
        specialistMapper.deleteById(specialistId);
        return ResultResponse.SUCCESS();
    }


}




